package device

import (
	"io/ioutil"
	"net/http"
	"strconv"

	"suci-go-zero/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
	"github.com/zeromicro/go-zero/rest/httpx"
)

func FirmwareUpgradeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		// var req types.OtaInfo
		// if err := httpx.Parse(r, &req); err != nil {
		// 	result.ParamErrorResult(r, w, err)
		// 	return
		// }
		// //判断是否能升级
		// l := device.NewFirmwareUpgradeLogic(r.Context(), svcCtx)
		// err := l.FirmwareUpgrade(&req)

		// if err != nil {
		body, err := ioutil.ReadFile("./static/hardwire/dfota_final_bmcx-2_bmcx-2_20230227102826_238325.bin")
		if err != nil {
			logx.Info("xxxxxxxxxxxxxxxxxxxx")
			httpx.Error(w, err)
			return
		}
		logx.Info(len(body), string(body[:128]))
		// w.Header().Set(ContentType, header.JsonContentType)
		// w.Header().Set("Content-Type", "application/octet-stream")
		w.Header().Set("Content-Type", "application/octet-stream")
		w.Header().Set("Content-Length", strconv.Itoa(len(body)))

		w.Write(body)
		// } else {
		// result.HttpResult(r, w, nil, err)

		// }
	}
}
